// 系统日志模块API

import api from '../index';
import {
  ApiResponse,
  SysLogQueryParams,
  SysLog,
  SysLogListResponse,
} from '../../types';

// 获取系统日志历史
export const getSysLogs = async (
  params: SysLogQueryParams = {}
): Promise<ApiResponse<SysLogListResponse>> => {
  const queryParams = new URLSearchParams();
  
  if (params.page) queryParams.append('page', params.page.toString());
  if (params.size) queryParams.append('size', params.size.toString());
  if (params.userId) queryParams.append('userId', params.userId.toString());
  if (params.requestMethod && params.requestMethod !== 'all') {
    queryParams.append('requestMethod', params.requestMethod);
  }
  if (params.operation && params.operation !== 'all') {
    queryParams.append('operation', params.operation);
  }
  if (params.errorOnly !== undefined) {
    queryParams.append('errorOnly', params.errorOnly.toString());
  }

  const response = await api.get(`/sys-logs?${queryParams.toString()}`);
  return response.data;
};

// 获取系统日志详情
export const getSysLogDetail = async (
  logId: number
): Promise<ApiResponse<SysLog>> => {
  const response = await api.get(`/sys-logs/${logId}`);
  return response.data;
}; 